#include "stdafx.h"
#include "input_data.hpp"
#include <iostream>

const char* input_ingdirect_data::pinpad_sequence = "\nIMMETTERE LA SEQUENZA DEL TASTIERINO:\n(10 numeri senza separazioni, da sinistra a destra, dall'alto al basso)";
//const char* pinpad_msg =  "Enter pinpad sequence, ten numbers without spaces,\nfrom top to bottom, from left to right:"
const char* input_ingdirect_data::pin_sequence = "\nIMMETTERE L'ORDINE DELLE CIFRE RICHIESTE:\n(3 numeri da 1-6 senza separazioni)";
//std::cout << "Shall we change input sequence? [n/y]" << std::endl << ">";
const char* input_ingdirect_data::is_correct_sequence = "\n>Correggere la sequenza immessa [";
//std::cout << "Enter 'y' to continue after page is complete; or 'n' to exit [y/n]:" << std::endl << ">";
const char* input_wait_state_data::is_complete_page = "\nA pagina completa, premere 's' per continuare; o 'n' per uscire [N/s]: ";
const char* input_wait_state_data::is_token_ready = "\nA supporto di decifrazione inserito, premere 's' per continuare; o 'n' per uscire [N/s]: ";


bool input_data::wait_ready_state_token()
{
	std::string _is_token(input_wait_state_data::is_token_ready);
	return wait_ready_state(_is_token);
}

bool input_data::wait_ready_state_interactive()
{
	std::string _is_complete(input_wait_state_data::is_complete_page);
	return wait_ready_state(_is_complete);
}


bool input_data::wait_ready_state(std::string const& _str)
{
	char c;
	std::cin.clear();

	do
	{				 		
		std::cout << _str;		
		std::cin.get(c);
		std::cin.ignore(256, '\n');

		switch(c)
		{
		case 'y': case 'Y': case 's': case 'S': return true;		
		default:  return false;
		}
		
	} while(true);

	return false;
}


const std::string input_data::get_pin_sequence()
{
	return input_data::get_input_sequence(&input_ingdirect_data::pin_sequence, 3);
}

const std::string input_data::get_pinpad_sequence()
{
	return input_data::get_input_sequence(&input_ingdirect_data::pinpad_sequence, 10);
}


const std::string input_data::get_input_sequence(const char** _input_message, unsigned short _len)
{
	std::string input;
	std::cin.clear();
	char c;
	
	do
	{		
		std::cout << ">" <<*_input_message << std::endl << ">";
		std::cin >> input;
		std::cin.ignore(256, '\n'); 		
		std::cout << input_ingdirect_data::is_correct_sequence << input << "] [N/s]: ";
		//std::cin >> c; 
		std::cin.get(c);
		std::cin.ignore(256, '\n'); 		

		switch(c)
		{
		case 'y': case 'Y': case 's': case 'S': 
			continue; 
		default: break;
		}
	} while( input.length() != _len );

	return input;
}



